package com.example.springdemo.listner;

import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @description:
 * @author: dengPing.xu
 * @date: 2022-04-02
 */
@Component
public class MyServletListener implements ServletContextListener {
    ServletContext servletContext;
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        servletContext = sce.getServletContext();
        this.servletContext.setAttribute("age", 18);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        servletContext = null;
    }
}
